package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.agentoperationportvo.AgentOperationPortCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.agentoperationportvo.AgentOperationPortPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.agentoperationportvo.AgentOperationPortRespVO;
import com.cmc.cloud.cmclink.doc.vo.agentoperationportvo.AgentOperationPortUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmes.framework.common.pojo.PageResult;

import com.cmc.cloud.cmclink.doc.entity.AgentOperationPortDO;
import com.cmc.cloud.cmclink.doc.service.AgentOperationPortService;


/**
 * {table.classComment}前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 单证代理操作口岸配置")
@RestController
@RequestMapping(UrlConstants.APPLICATION_URL+"/operation")
@Validated
public class AgentOperationPortController {

    @Resource
    private AgentOperationPortService agentOperationPortService;

    @Operation(summary = "创建单证代理操作口岸配置")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission('doc:agentOperationPort:add')")
    public CommonResult<Void> createAgentOperationPort(@Valid @RequestBody AgentOperationPortCreateReqVO createReqVO) {
        agentOperationPortService.createAgentOperationPort(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新单证代理操作口岸配置")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission('doc:agentOperationPort:edit')")
    public CommonResult<Void> updateAgentOperationPort(@Valid @RequestBody AgentOperationPortUpdateReqVO updateReqVO) {
        agentOperationPortService.updateAgentOperationPort(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除单证代理操作口岸配置")
    @Parameter(name = "id", description = "编号", required = true)
    @PostMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermission('doc:agentOperationPort:delete')")
    public CommonResult<Void> deleteAgentOperationPort(@PathVariable("id") Long id) {
        agentOperationPortService.deleteAgentOperationPort(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得单证代理操作口岸配置")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @GetMapping("/getById/{id}")
    public CommonResult<AgentOperationPortRespVO> getAgentOperationPort(@PathVariable("id") Long id) {
        AgentOperationPortDO agentOperationPort = agentOperationPortService.getAgentOperationPort(id);
        return CommonResult.success(BeanUtil.copyProperties(agentOperationPort, AgentOperationPortRespVO.class));
    }

    @Operation(summary = "获得单证代理操作口岸配置列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @GetMapping("/listAll")
    public CommonResult<List<AgentOperationPortRespVO>> getAgentOperationPortList(@RequestParam("ids") Collection<Long> ids) {
        List<AgentOperationPortDO> list = agentOperationPortService.getAgentOperationPortList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, AgentOperationPortRespVO.class));
    }

    @Operation(summary = "获得单证代理操作口岸配置分页")
    @UseResponsePropertyAdvice
    @PostMapping("/getPage")
    @PreAuthorize("@ss.hasPermission('doc:agentOperationPort:search')")
    public CommonResult<PageResult<AgentOperationPortRespVO>> getAgentOperationPortPage(@Valid @RequestBody AgentOperationPortPageReqVO pageVO) {
        PageResult<AgentOperationPortRespVO> pageResult = agentOperationPortService.getAgentOperationPortPage(pageVO);
        return CommonResult.success(pageResult);
    }
}
